<?php
namespace common\widgets\modal;
/**
 * @link http://www.yii-china.com/
 * @copyright Copyright (c) 2016 yii-china.com
 * @license http://www.yii-china.com/doc/hyii2.html
 * @author Xianan Huang <xianan_huang@163.com>
 */
use Yii;
use yii\bootstrap\Widget;
class ModalWidget extends Widget
{
    /**
     * 触发ID
     * @var unknown
     */
    public $id;
    
    /**
     * 标题
     * @var unknown
     */
    public $title = '';
    
    /**
     * 请求地址
     * @var unknown
     */
    public $requestUrl;
    
    public $data = [];
    
    public function init()
    {
        $data = json_encode($this->data);
        $js = 
        <<<JS
        $('{$this->id}').click(function () {
            $('.modal-title').html('{$this->title}');
            $.ajax({
                url: "{$this->requestUrl}",
                type: "get",
                data: '{$data}',
                success: function(data) {
                    $('.modal-body').html(data);
                },
                beforeSend:function(){
            		$('.modal-body').html('加载中...');
            	}
            });
        });
JS;
    $this->view->registerJs($js);
    }
}